package com.easylinkin.linkappapi.circuit.controller;

import com.easylinkin.linkappapi.circuit.dto.RailCircuitGivealarmDTO;
import com.easylinkin.linkappapi.circuit.service.IRailCircuitGivealarmService;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * 断路器报警/故障信息接口类
 * @author lyk
 * @date 2025/6/16 下午 2:43
 */
@RestController
@RequestMapping("/circuitGivealarm")
public class RailCircuitGivealarmController {

    @Resource
    private IRailCircuitGivealarmService railCircuitGivealarmService;

     /**
     * 饼图统计和报警故障总和查询
     * @return
     */
    @GetMapping(value = "/findTotalByPieChart")
    public RestMessage findTotalByPieChart(){
        Map<String,Object>  result = railCircuitGivealarmService.findTotalByPieChart();
        return RestBuilders.successBuilder().data(result).build();
    }

    /**
     * 根据报警故障类型返回每个类型是树状图数据
     * @param railCircuitGivealarmDTO
     * {
     *     deviceCode:设备唯一编码
     *     cumulative: 0:一月 默认一月 1:开累
     * }
     * @return
     */
    @PostMapping(value = "/faultTypeByColumnar")
    public RestMessage faultTypeByColumnar(@RequestBody RailCircuitGivealarmDTO railCircuitGivealarmDTO){
        if (Objects.isNull(railCircuitGivealarmDTO.getCumulative())){
            railCircuitGivealarmDTO.setCumulative(0);
        }
        Map<String,Object>  result = railCircuitGivealarmService.faultTypeByColumnar(railCircuitGivealarmDTO);
        return RestBuilders.successBuilder().data(result).build();
    }



}
